import request from '@/utils/request'

export function getOrderList() {
  return request({
    url: '/orders/list',
    method: 'get',
  })
}


// 创建订单(点击购物按钮)
export const createOrderBuynow = (orderData) => {
  return request({
    url: '/orders/Buynow',
    method: 'post',
    data: {
      bookId: orderData.bookId,
      quantity: orderData.quantity,
      addressId: orderData.addressId,
      orderStatus: orderData.orderStatus,// 订单状态
      payMethod: orderData.payMethod,

    }
  })
}


// 购物车结算
export const createOrderFromCart = (orderData) => {
  // 在调用API前处理数据
  // const cartItems = orderData.CartIds.map(item => item.cartId);

  return request({
    url: '/orders/create',
    method: 'post',
    data: {
      cartIds: orderData.CartIds,
      addressId: orderData.addressId,
      orderStatus: orderData.orderStatus,// 订单状态
      payMethod: orderData.payMethod,

    }
  })
}


//待支付订单点击去支付的请求,变成待收货状态2
export const payOrder = (orderId) => {
  return request({
    url: '/orders/UpdateOrderStatus',
    method: 'get',
    params: {
      orderId: orderId,
      status: 2,
    }
  })
}


//删除订单（售后完成、已完成、已取消的订单执行的）
export const deleteOrder = (orderId) => {
  return request({
    url: '/orders/deleteOrderById',
    method: 'get',
    params: {
      orderId: orderId,
    }
  })
}

// 取消订单(待支付、待发货、待收货订单执行的，然后变成已取消状态5)
export const UpdateOrderStatusToCancel = (orderId) => {
  return request({
    url: '/orders/UpdateOrderStatus',
    method: 'get',
    params: {
      orderId: orderId,
      status: 5,
    }
  })
}

// 确认收货(待收货订单执行的，然后变成已完成状态4)
export const UpdateOrderStatusToComplete = (orderId) => {
  return request({
    url: '/orders/UpdateOrderStatus',
    method: 'get',
    params: {
      orderId: orderId,
      status: 4,
    }
  })
}

// 申请售后
export const applyAfterSale = (orderData) => {
  return request({
    url: '/orders/aftersales',
    method: 'post',
    data: {
      orderId: orderData.orderId, // 订单id，与实体类中orderId对应
      userId: orderData.userId, // 用户id，与实体类中userId对应
      reason: orderData.reason    // 申请原因，与实体类中Reason对应（注意实体类里属性首字母大写，这里保持一致）
    }
  })
}


